﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DLV.Data.Entities;
using DLV.FrameWork;

namespace DLV.BackEnd.Pages
{
    public partial class ChiettinhKhachSan : AdminPageBase
    {

        protected List<CalculatorInfo> TicketHotel = new List<CalculatorInfo>();
        protected decimal TotalTicketHotelPrices = 0;
        protected decimal TotalTicketHotelPricesAdults = 0;
        protected decimal TotalTicketHotelPricesChild = 0;


        private List<CalculatorInfo> _calculatorList = new List<CalculatorInfo>();
        private readonly CalculatorController _calculatorController = new CalculatorController();
        protected TourInfo tourInfo = new TourInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!String.IsNullOrEmpty(Request.QueryString["TourId"]))
            {
                _calculatorList =
                    _calculatorController.ListCalculator()
                        .Where(p => p.TourId == int.Parse(Request.QueryString["TourId"])).ToList();
                tourInfo = new TourController().GetTour(int.Parse(Request.QueryString["TourId"]));
            }
            LoadHotelType();
            LoadNational();
            if (_calculatorList.Count == 0) return;
            RenderForm();
        }

        public void RenderForm()
        {

            if (!String.IsNullOrEmpty(Request.QueryString["TourId"]))
            {
                TicketHotel = _calculatorList.Where(p => p.ItemType == 5).ToList();
                TotalTicketHotelPricesAdults = TicketHotel.Sum(p =>p.TotalPriceHotelAdults);
                TotalTicketHotelPricesChild = TicketHotel.Sum(p => p.TotalPriceHotelChild);
                TotalTicketHotelPrices = TotalTicketHotelPricesAdults + TotalTicketHotelPricesChild;

            }
        }

        public void LoadHotelType()
        {
            ddlHotelType.DataSource = new HotelTypeController().ListHotelType().OrderBy(p=>p.HotelTypeName);
            ddlHotelType.DataValueField = "HotelTypeId";
            ddlHotelType.DataTextField = "HotelTypeName";
            ddlHotelType.DataBind();

            ddlHotelType.Items.Insert(0,new ListItem("--Chọn loại--","-1"));
        }
        public void LoadNational()
        {
            ddlNational.DataSource = new NationalController().ListNational().OrderBy(p => p.NationalName);
            ddlNational.DataValueField = "NationalId";
            ddlNational.DataTextField = "NationalName";
            ddlNational.DataBind();

            ddlNational.Items.Insert(0, new ListItem("--Chọn quốc gia--", "-1"));
        }
    }
}